package cn.gok.thread;

/**
 * @ClassName 线程join例子
 * @Description TODO
 * @Author HP
 * @Date 10:27 2022/7/13
 * @Version 1.0
 **/
class C extends Thread{
    private D d;
    public C (D d){
        this.d=d;
    }
    @Override
    public void run() {
        System.out.println("ccccc");
        try {
            d.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("线程c结束");

    }
}
class D extends Thread{
    @Override
    public void run() {
        System.out.println("ddddd");
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("线程d结束");
    }

}


public class 线程join例子 {
    public static void main(String[] args) {
        D d = new D();
        C c = new C(d);
        d.start();
        c.start();
    }
}
